/**
 * Created by gongxun on 17/1/13.
 */

var GsbdxCard = cc.Sprite.extend({
    mCardNum : null,
    mNumSprite : null,

    mKind : null,
    mSeat : null,
    ctor : function(){
        this._super();
        this.setAnchorPoint(cc.p(0.5, 0));

        this.mNumSprite = new cc.Sprite();
        this.addChild(this.mNumSprite);
    },

    setCardNum : function(num){
        if (mo.gsbdxCardHelper.getExistCardNum(num)){
            this.mCardNum = num;
        }else{
            this.mCardNum = 0;
        }
    },

    //kind 1:inhand 2:cardwell
    setCardKind : function(seat, kind){
        if (kind == 1){
            if (this.mCardNum != 0){
                this.setSpriteFrame(this.getImageFileName("cardOpen.png"));
                this.mNumSprite.setSpriteFrame("ttz_card" + this.mCardNum + ".png");
                this.mNumSprite.setVisible(true);
                this.setNumSpritePos(cc.p(0, 7));

            }else{
                this.setSpriteFrame(this.getImageFileName("cardHide.png"));
                this.mNumSprite.setVisible(false);
            }
            this.setScale(seat == 0 ? mo.gsbdxCardHelper.inhandMyScale : mo.gsbdxCardHelper.inhandScale);
        }else if (kind == 2){
            if (this.mCardNum != 0){
                this.setSpriteFrame(this.getImageFileName("cardOpen.png"));
                this.mNumSprite.setSpriteFrame("ttz_card" + this.mCardNum + ".png");
                this.mNumSprite.setVisible(true);
                this.setNumSpritePos(cc.p(0, 7));

            }else{
                this.setSpriteFrame(this.getImageFileName("cardHide.png"));
                this.mNumSprite.setVisible(false);
            }
            this.setScale(mo.gsbdxCardHelper.cardWellScale);
        }
    },

    getImageFileName : function(name){
        return "ttz_" + name;
    },

    setNumSpritePos : function(p) {
        var size = this.getContentSize();
        this.mNumSprite.setPosition(cc.p(size.width / 2 + p.x, size.height / 2 + p.y));
    },

    getCarcJisuanNum : function(){
        var num = this.mCardNum - 1;
        var temp = num % 13;
        temp += 1;
        if (temp > 10){
            temp = 10;
        }

        //王
        if (this.mCardNum >= 53){
            temp = 10;
        }

        return temp;
    },

    //返回牌花色 0:tao 1:xin 2:mei 3:fang
    getCardSuit : function(num){
        var temp = num - 1;
        return parseInt(temp / 13);
    }
});